<!-- 移动单个笔记 -->
{% init callback = "defaultMoveNoteCallback" %}

<div class="group-select-search">
    <input id="groupSelectInput" type="text" class="nav-search-input" placeholder="搜索项目"/>
    <button class="nav-search-btn btn-default">
        <i class="fa fa-search"></i>
    </button>
</div>

<div class="note-group-select col-md-12 scroll-y">
    {% for category, groups in groups_tuple %}
        {% if len(groups) == 0 %}
            {% continue %}
        {% end %}

        <h3 class="group-select-header">{{category}}</h3>

        {% for item in groups %}
            <p class="group-select-row">
                <i class="fa {{item.icon}}"></i>
                <a class="link" href="javascript:{{callback}}('{{item.id}}', '{{id}}')">
                    {{item.path or item.name}}
                </a>
                <span class="group-select-size">{{item.children_count}}</span>
            </p>
        {% end %}
    {% end %}
</div>

<script type="text/javascript">
$(function () {
    $("#groupSelectInput").unbind("keyup");
    $("#groupSelectInput").keyup(function(event) {
        /* Act on the event */
        var searchKey = $(this).val();
        $(".group-select-row").show();

        if (searchKey == "") {
            return;
        }

        $(".group-select-row").each(function (index, element) {
            var noteName = $(element).children("a").text();
            if (noteName.indexOf(searchKey) < 0) {
                $(this).hide();
            }
        })
    });


    // 移动笔记
    window.defaultMoveNoteCallback = function (parentId, noteId) {
        if (noteId === undefined || noteId == "") {
            xnote.alert("noteId is undefined");
            return;
        }
        $.post("/note/move", {id:noteId, parent_id: parentId}, function (resp){
              console.log(resp);
              window.location.reload();
        });
    }

})
</script>
